<%@page contentType="text/html; charset=utf-8"%>
<%@include file="/WEB-INF/views/common/taglibs.jspf" %>

<link rel="stylesheet" href="${ctx}/static/plugins/jqwidgets/jqwidgets/styles/jqx.base.css" />
<link rel="stylesheet" href="${ctx}/static/plugins/jqwidgets/jqwidgets/styles/jqx.arctic.css" />

<title>分配资源</title>

<div style="padding:12px;">
	<div class="row">
		<div class="col-xs-12">
		<!-- PAGE CONTENT BEGINS -->
			<input type="hidden" id="roleId" value="${id}">
			<div id="treeGrid"></div>
				
		<!-- PAGE CONTENT ENDS -->
		</div><!-- /.col -->
	</div><!-- /.row -->
</div>
<script type="text/javascript">
var scripts = [null, 
               "${ctx}/static/plugins/jqwidgets/jqwidgets/jqxcore.js", 
               "${ctx}/static/plugins/jqwidgets/jqwidgets/jqxbuttons.js", 
               "${ctx}/static/plugins/jqwidgets/jqwidgets/jqxdata.js", 
               "${ctx}/static/plugins/jqwidgets/jqwidgets/jqxscrollbar.js", 
               "${ctx}/static/plugins/jqwidgets/jqwidgets/jqxdatatable.js", 
               "${ctx}/static/plugins/jqwidgets/jqwidgets/jqxtreegrid.js", 
               null];
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
	jQuery(function($) {
		var source = {
				dataType: "json", url: "${ctx}/admin/sys/resource/allotPermiss",
				id: "id", hierarchy: {root: "children"},
				dataFields: [
					{name: "id", type: "number"},
					{name: "name", type: "string"},
					{name: "href", type: "string"},
					{name: "identity", type: "string"},
					{name: "weight", type: "number"},
					{name: "show", type: "string"},
					{name: "parentIds", type: "string"},
					{name: "parentId", type: "string"}, 
					{name: "children", type: "string"}, 
					{name: "operations", type: "string"}, 
					{name: "expanded", type: "bool"}, 
				]
		};
		var dataAdapter = new $.jqx.dataAdapter(source);
		jqxTg = $("#treeGrid").jqxTreeGrid({
			source: dataAdapter,
			columnsHeight: 50,
			width: "full", height: 400, 
	        ready: function() {
	        	$(".selectAll").on("click", function() {
	        		if($(this).prop("checked") == true) {
	        			$("."+$(this).attr("id")+"").prop("checked", true) ;
	        		} else {
	        			$("."+$(this).attr("id")+"").prop("checked", false) ;
	        		}
	        	});
	        	$.get("${ctx}/admin/sys/role_resource/get/${id}", function(result){
	    			if(undefined != result.resourceIds && "" != result.resourceIds.trim()) {
	    				$.each(result.resourceIds.split(","), function(i, v) {
	    					$("input[type=checkbox][name=id][value="+v+"]").prop("checked", true) ;
	    				});
	    			}
	    		}, "JSON");
	        },
			columns: [
				//{text: "编号", dataField: "id", width: 100},
				{text: "名称", dataField: "name", width: 180},
				{text: "操作", dataField: "aa", cellsRenderer: function (index, column, value, rowData){
					var opers = "" ;
					if(undefined != rowData.operations && rowData.operations.length > 0) {
						opers = '<label><input type="checkbox" class="ace ace-checkbox-2 selectAll" id="sel'+index+'"><span class="lbl">全选</span></label>&nbsp;&nbsp;&nbsp;&nbsp;' ;
						
						$.each(rowData.operations, function(i, p) {
							var checkbox = '<label><input type="checkbox" class="ace ace-checkbox-2 sel'+index+'" name="id" value="'+p.id+'"><span class="lbl"> '+p.name+'</span></label>&nbsp;&nbsp;' ;
							opers += checkbox ;
						});
					}
					return opers ; 
				}},
			]
		});
		
		
		
		
		
		
		
		
		
		
		
	});
});

</script>
